AC_PREREQ(2.59)
AC_INIT([PeRIPLO 1.0], [simone.rollini@gmail.com])
AC_CONFIG_AUX_DIR(autotools)
AM_INIT_AUTOMAKE([subdir-objects])
AC_CONFIG_MACRO_DIR([m4])

AC_PROG_CC
AC_PROG_CXX
AC_PROG_YACC
AM_PROG_LEX
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET

LT_INIT

#
# Check the availability of tr1
#
AC_CHECK_HEADERS(tr1/unordered_map, tr1/unordered_set, , [AC_MSG_ERROR([TR1 was not found.])])
			     
#
# Libraries generation
#			     
AC_ARG_ENABLE(library,
  AC_HELP_STRING([--enable-library],
                 [produces PeRIPLO libraries (default=no)]),
  want_library="yes",
  want_library="no")

AM_CONDITIONAL([WANT_LIBRARY], [test "$want_library" = "yes"])

#
# Statically linked version
#
AC_ARG_ENABLE(statically,
  AC_HELP_STRING([--enable-statically],
                 [enable statically linked libraries (-static) (default=no)]),
  enablestatically=$enableval,
  enablestatically="no")

if test $enablestatically = "yes" ;
then
  config_statically="-static"
elif test $enablestatically = "no" ;
then
  config_statically="" 
else
  config_statically=$enablestatically
fi
echo "setting static flags to... ${config_statically:-none}"
# 
# Profiling
#
AC_ARG_ENABLE(profiling,
  AC_HELP_STRING([--enable-profiling],
                 [enable profiling (-pg) (default=no)]),
  enableprofiling=$enableval,
  enableprofiling="no")

if test $enableprofiling = "yes" ;
then
  config_profiling="-pg"
elif test $enableprofiling = "no" ;
then
  config_profiling=""
else
  config_profiling=$enableprofiling
fi
echo "setting profiling flags to... ${config_profiling:-none}"
#
# Optimization
#
AC_ARG_ENABLE(optimization,
  AC_HELP_STRING([--enable-optimization],
                 [enable optimization by compiler (-O3) (default=yes)]),
  enableoptimization=$enableval,
  enableoptimization="yes")

if test $enableoptimization = "yes" ;
then
  config_optimization="-O3 -DOPTIMIZE -DNDEBUG"
elif test $enableoptimization = "no" ;
then
  config_optimization="-O0"
else
  config_optimization=$enableoptimization
fi
echo "setting optimization flags to... ${config_optimization:-none}"
#
# Proof production
#
AC_ARG_ENABLE(proof,
  AC_HELP_STRING([--enable-proof],
                 [enable proof production (default=no)]),
  enableproof=$enableval,
  enableproof="no")

if test $enableproof = "yes" ;
then
  config_proof="-DPRODUCE_PROOF"
elif test $enableproof = "no" ;
then
  config_proof=""
else
  config_proof=$enableproof
fi
echo "setting proof flags to... ${config_proof:-none}"
#
# Full labeling system for interpolation
#
AC_ARG_ENABLE(fulllabeling,
  AC_HELP_STRING([--enable-fulllabeling],
                 [enable full labeling system (default=no)]),
  enablefulllabeling=$enableval,
  enablefulllabeling="no")

if test $enablefulllabeling = "yes" ;
then
  config_fulllabeling="-DFULL_LABELING"
elif test $enablefulllabeling = "no" ;
then
  config_fulllabeling=""
else
  config_fulllabeling=$enablefulllabeling
fi
echo "setting full labeling system flags to... ${config_fulllabeling:-none}"

AM_CFLAGS="-W -Wall -g -Wno-deprecated $config_profiling $config_optimization $config_statically  $config_proof $config_fulllabeling"
AM_CXXFLAGS="-W -Wall -g -Wno-deprecated $config_profiling $config_optimization $config_statically $config_proof $config_fulllabeling"
CFLAGS=""
CXXFLAGS=""

# Allow user to use a GMP lib in a non-standard location
AC_ARG_WITH([gmp],
	    [AS_HELP_STRING([--with-gmp=prefix],
			    [Use this when GMP is in a non-standard location])],
			    [NONSTDGMPPATH=1],
			    [NONSTDGMPPATH=0])
if test $NONSTDGMPPATH = 1 ; then
  AM_CXXFLAGS="$AM_CXXFLAGS -I$with_gmp"
  AM_LDFLAGS="$AM_LDFLAGS -L$with_gmp/.libs"
fi

AC_SUBST(AM_CFLAGS)
AC_SUBST(AM_CXXFLAGS)
AC_SUBST(CFLAGS)
AC_SUBST(CXXFLAGS)
AC_SUBST(AM_LDFLAGS)

# Setup comilation/linking flags for library checks
OLDCPPFLAGS=$CPPFLAGS
CPPFLAGS=$CXXFLAGS
OLDLDFLAGS=$LDFLAGS
LDFLAGS="$LDFLAGS $AM_LDFLAGS"

# Check for GMP header
GMP_HEADER_FOUND=1
if test $NONSTDGMPPATH = 1 ; then
	AC_CHECK_HEADERS($with_gmp/gmp.h,
			 ,
			 [AC_MSG_ERROR([ The GMP header gmp.h was not found.])])

else
	AC_CHECK_HEADERS(gmp.h,
			 ,
			 [AC_MSG_ERROR([ The GMP header gmp.h was not found.])])
fi
# Check for GMP library
AC_CHECK_LIB(gmp, __gmpz_init, ,[AC_MSG_ERROR([GMP library not found])])

# Restore original flags
CPPFLAGS=$OLDCPPFLAGS
LDFLAGS=$OLDLDFLAGS

#
# List of directories to include
#
config_includedirs="-I\${top_srcdir}/src \\\
-I\${top_srcdir}/src/minisat \\\
-I\${top_srcdir}/src/minisat/core \\\
-I\${top_srcdir}/src/minisat/utils \\\
-I\${top_srcdir}/src/minisat/simp \\\
-I\${top_srcdir}/src/minisat/mtl \\\
-I\${top_srcdir}/src/satsolvers \\\
-I\${top_srcdir}/src/simplifiers \\\
-I\${top_srcdir}/src/common \\\
-I\${top_srcdir}/src/egraph \\\
-I\${top_srcdir}/src/sorts \\\
-I\${top_srcdir}/src/cnfizers \\\
-I\${top_srcdir}/src/proof \\\
-I\${top_srcdir}/src/api "


AC_SUBST(config_includedirs)

AC_CONFIG_FILES([ \
		  Makefile \
		  src/Makefile \
		  src/parsers/Makefile \
		  src/parsers/smt2/Makefile \
		  src/cnfizers/Makefile \
		  src/satsolvers/Makefile \
		  src/simplifiers/Makefile \
		  src/proof/Makefile \
		  src/egraph/Makefile \
		  src/sorts/Makefile \
		  src/api/Makefile \
		  ])

AC_OUTPUT
